home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_10 / saks / comq6.h < prev    next >
C/C++ Source or Header  |  1994-08-08  |  1KB  |  64 lines

  1. Listing 5 - class and inline member function definitions for a generic 
  2. queue of common *
  3.  
  4. //
  5. // comq6.h - generic queue of common *
  6. // with an iterator class
  7. //
  8.  
  9. #include "common.h"
  10.  
  11. class comq
  12.     {
  13. private:
  14.     struct cell
  15.         {
  16.         cell(const common &e, cell *p);
  17.         ~cell();
  18.         cell *next;
  19.         common *element;
  20.         };
  21.     cell *first, *last;
  22. public:
  23.     comq();
  24.     ~comq();
  25.     void append(const common &e);
  26.     void clear();
  27.     int remove(common &e);
  28.     class iterator;
  29.     friend class iterator;
  30.     class iterator
  31.         {
  32.     public:
  33.         iterator(comq &q);
  34.         common *next();
  35.     private:
  36.         cell *pc;
  37.         };
  38.     };
  39.  
  40. inline comq::cell::cell(const common &e, cell *p)
  41.     : element(e.dup()), next(p)
  42.     {
  43.     }
  44.  
  45. inline comq::cell::~cell()
  46.     {
  47.     delete element;
  48.     }
  49.  
  50. inline comq::iterator::iterator(comq &q)
  51.     : pc(q.first)
  52.     {
  53.     }
  54.  
  55. inline comq::comq() : first(0), last(0)
  56.     {
  57.     }
  58.  
  59. inline comq::~comq()
  60.     {
  61.     clear();
  62.     }
  63.  
  64.